<template>
    <el-container>
        <el-container class="is-vertical">
            <div class="panel-search-box">
                <div class="panel-search">
                    <el-date-picker v-model="search.createdAt" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"
							range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" class="sDateSelect" style="margin-left:10px;"
						></el-date-picker>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                    <el-button type="primary" icon="el-icon-download" @click="exportHander">导出</el-button>
                </div>
            </div>
            <el-main class="nopadding" style="min-height:600px;">
                <scDialogTable ref="table" :apiObj="$API.teacher.brokerage.list" remoteSort :params="search" @selection-change="selectionChange" @dataChange="dataChange" :height="600" :exportData="exportData" :formatExportData="formatExportData">
                    <el-table-column label="序号" prop="index" width="70" align="left"></el-table-column>
                    <el-table-column label="来源用户" prop="user" align="center">
                        <template #default="scope">
                            {{ scope.row.user ? scope.row.user.name : '' }}
                        </template>
                    </el-table-column>
                    <el-table-column label="充值金额" prop="rechargeAmount" align="center" width="140">
                    </el-table-column>
                    <el-table-column label="返利金额" prop="amount" width="140" align="center">
                    </el-table-column>
                    <el-table-column label="返利时间" prop="createdAt" width="150" align="center"></el-table-column>
                </scDialogTable>
            </el-main>
        </el-container>
    </el-container>

</template>

<script>
import { in_array } from '@/utils/index.js'
export default {
    components: {
    },
    props: {
        teacherId: {type: Number, default: 0}
    },
    data() {
        return {
            in_array,
            selection: [],
            search: {
                teacherId: 0,
            },
            exportData: {
                header: ['来源用户', '充值金额', '返利金额', '返利时间'],
                column: ['userName', 'rechargeAmount', 'amount', 'createdAt'],
                filename: '教练返利列表',
                formatData: true
            },
        }
    },
    mounted() {
       if (this.teacherId) {
            this.search.teacherId = this.teacherId
        }
    },
    methods: {
        dataChange(res, tableData) {
			let total = res.data.total
            let perPage = res.data.perPage
            let page = (this.$refs.table && this.$refs.table.currentPage) || 1
            tableData.forEach((item, index) => {
				item.index = page * perPage + index - perPage + 1
            })
        },
        // 搜索
        upsearch() {
            this.$refs.table.upData(this.search)
        },
        exportHander() {
			this.$refs.table.exportHander(this.search)
		},
		formatExportData(item) {
            item.userName = item.user ? item.user.name : ''
            return item
        },
        //表格选择后回调事件
        selectionChange(selection) {
            this.selection = selection;
        },
        //本地更新数据
        handleSuccess() {
            this.$refs.table.refresh()
        }
    }
}
</script>

<style>
</style>
